/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"235C535F-C426-44BB-A57A-745C6736FC1F",variableType:4}
 */
var $historico = 0;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"D2693D83-5ADD-4C53-83C0-9CE8D31F79B7",variableType:4}
 */
var $historico_listado_perfiles = 1;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"03B56C10-6A87-454B-849A-91D4C875568C",variableType:4}
 */
var $historico_listado_usuarios = 2;

/**
 * @properties={typeid:24,uuid:"F5A65C74-43AD-4391-A77D-48BE8CE64DF3"}
 */
function doEdit(){
	
	elements.group_tab_historico.visible = false;
	controller.focusField(elements.fld_s_descripcion.getName(),true);
}

/**
 * @properties={typeid:24,uuid:"B9B97B36-E33E-402D-8AC3-9333E4AADDD3"}
 */
function hide_btn_reset_fields(){
	
	elements.group_tab_historico.visible = true;
}

/**
 * Opciones propias del menú
 * @author Roberto J. Blasco
 * @version 1.0
 * @param event
 *
 * @properties={typeid:24,uuid:"06F94BF1-74A3-43F5-8EF1-88B2A24EE9D1"}
 */
function opciones(event){
	
	var submenu_alta_perfil = $menu.addMenuItem("Alta Perfil", alta_perfil);
	submenu_alta_perfil.methodArguments = [event, foundset.getSelectedRecord()];
	var submenu_alta_usuario = $menu.addMenuItem("Alta Usuario", alta_usuario);
	submenu_alta_usuario.methodArguments = [event, foundset.getSelectedRecord()];
}

/**
 * Alta de un nuevo Perfil
 * @author Roberto J. Blasco
 * @version 1.0
 * @private 
 * @properties={typeid:24,uuid:"C2F14868-9F4E-4318-AFFE-1693CE97DAE7"}
 */
function alta_perfil(){
	
	
}

/**
 * Alta de un nuevo Usuario
 * @author Roberto J. Blasco
 *  @version 1.0
 *  @private 
 * @properties={typeid:24,uuid:"E8FE10A4-F13B-4AF4-A962-792E40197E0A"}
 */
function alta_usuario(){
	
	
}

/**
 * Handle changed data.
 *
 * @param {Number} oldValue old value
 * @param {Number} newValue new value
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @private
 *
 * @properties={typeid:24,uuid:"C32467A4-AAF9-4640-93F6-18CFA223C460"}
 */
function onDataChangeHistorico(oldValue, newValue, event) {

	elements.tab_historicos.removeAllTabs();
	if ($historico == $historico_listado_perfiles){
		elements.tab_historicos.addTab(forms.lst_adm_t900_perfiles_h,null,null,null,null,null,null, adm_t900_empresas_to_adm_t900_perfiles);
	}else if  ($historico == $historico_listado_usuarios){
		elements.tab_historicos.addTab(forms.lst_adm_t900_usuarios_h,null,null,null,null,null,null, adm_t900_empresas_to_adm_t900_usuarios);
	}
	return true
}

/**
 * Callback method for when form is shown.
 * @author Roberto J. Blasco
 * @version 1.0
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 * @private
 * @properties={typeid:24,uuid:"869F104E-28AF-4D81-B003-0B64D615A244"}
 */
function onShow(firstShow, event) {

	if (foundset.getSelectedRecord().isNew()){
		elements.tab_historicos.visible = false;
	}else{
		
		var dataset = databaseManager.createEmptyDataSet(0,new Array('display_values','optional_real_values'));
		dataset.addRow(['LISTADO DE PERFILES', $historico_listado_perfiles]);
		dataset.addRow(['LISTADO DE USUARIOS', $historico_listado_usuarios]);
		elements.historicos.setValueListItems(dataset);
		
		elements.tab_historicos.visible = true;
		elements.tab_historicos.removeAllTabs();
		elements.tab_historicos.addTab(forms.lst_adm_t900_perfiles_h,null,null,null,null,null,null,adm_t900_empresas_to_adm_t900_perfiles);
		$historico = $historico_listado_perfiles;
	}
}

/**
 * @param {JSEvent} event
 * @properties={typeid:24,uuid:"5E2C8B40-1A8A-49C4-B9D4-174729395769"}
 */
function eliminar_antes(event){
	
	var error = "";
	
	if (utils.hasRecords(foundset.getSelectedRecord().adm_t900_empresas_to_adm_t900_perfiles)){
		error += "La empresa tiene " +  adm_t900_empresas_to_adm_t900_perfiles.historico + " Perfiles. Si continúa, serán eliminados.";
	}
	
	if (utils.hasRecords(foundset.getSelectedRecord().adm_t900_empresas_to_adm_t900_usuarios)){
		error += "La empresa tiene " + adm_t900_empresas_to_adm_t900_usuarios.historico + " Usuarios. Si continúa, serán eliminados";
	}
	
	globals.$error = error;
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"4EA2D149-96B5-4A8C-A8A5-517FE5066D81"}
 */
function historico_opciones(event) {
	// TODO Auto-generated method stub
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"615B2CAF-EF0B-48D9-8CA4-74A245BD2D67"}
 */
function historico_alta(event) {

	/** @type {JSDataSet} */
	var ds = databaseManager.createEmptyDataSet();
	ds.addRow(['adm_t900_empresas_id', adm_t900_empresas_id]);
	
	if ($historico == $historico_listado_perfiles){
		globals.ir_formulario(forms.frm_adm_t900_perfiles.controller.getName(), null, globals.$MODO_ALTA,ds);
	}else if ($historico == $historico_listado_usuarios){
		globals.ir_formulario(forms.frm_adm_t900_usuarios.controller.getName(), null,  globals.$MODO_ALTA,ds);
	}
}
